<?php

namespace Tests\Console;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Symfony\Component\Console\Exception\RuntimeException;

class CreateUserTest extends TestCase
{
    use WithFaker;

    public function testSuccess()
    {
        $choice_ask = 'Which roles assign to this user?';
        $name_ask = 'What is your name?';
        $pass_ask = 'Type your password';
        \Artisan::command('user:create {login}', function () use ($choice_ask, $name_ask, $pass_ask) {
            $this->ask($name_ask);
            $this->secret($pass_ask);
            $this->choice($choice_ask, ['Guest', 'Admin', 'Moderator']);
        });
        $user_login = $this->faker->word();
        $this->artisan('user:create ' . $user_login)
            ->expectsQuestion($name_ask, $this->faker->name())
            ->expectsQuestion($pass_ask, $this->faker->password())
            ->expectsQuestion($choice_ask, 'Guest')
            ->assertSuccessful();
    }

    public function testFailed()
    {
        $this->expectException(RuntimeException::class);
        $this->artisan('user:create');
    }
}
